import { createRouter, createWebHashHistory } from 'vue-router';

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/hbMarket',
    },
    {
      path: '/bankCard',
      name: 'bankCard',
      meta: {
        title: '银行卡',
      },
      component: () => import('../views/bankCard/index.vue'),
      children: [
        {
          path: '/bankCard',
          redirect: '/bankCard/bankCardList',
        },
        {
          path: '/bankCard/bankCardList',
          name: 'bankCardList',
          meta: {
            title: '银行卡',
          },
          component: () => import('../views/bankCard/bankCardList.vue'),
        },
        {
          path: '/bankCard/bindBankCard',
          name: 'bindBankCard',
          meta: {
            title: '绑定银行卡',
          },
          component: () => import('../views/bankCard/bindBankCard.vue'),
        },
      ],
    },
    {
      path: '/hbMarket',
      name: 'hbMarket',
      meta: {
        title: '积分超市',
      },
      component: () => import('../views/hbMarket/index.vue'),
      children: [
        {
          path: '/hbMarket',
          redirect: '/hbMarket/home',
        },
        {
          path: '/hbMarket/home',
          name: 'hbMarketHome',
          meta: {
            title: '积分超市',
            keepAlive: true,
          },
          component: () => import('../views/hbMarket/pages/hbMarketHome.vue'),
        },
        {
          path: '/hbMarket/my',
          name: 'hbMarketMy',
          meta: {
            title: '我的',
            keepAlive: true,
          },
          component: () => import('../views/hbMarket/pages/hbMarketMy.vue'),
        },
        {
          path: '/hbMarket/productForm',
          name: 'productForm',
          meta: {
            title: '发布商品',
          },
          component: () => import('../views/hbMarket/pages/productForm.vue'),
        },
        {
          path: '/hbMarket/productSkuForm',
          name: 'productSkuForm',
          meta: {
            title: '规格参数',
          },
          component: () => import('../views/hbMarket/pages/productSkuForm.vue'),
        },
        {
          path: '/hbMarket/productDetail',
          name: 'productDetail',
          meta: {
            title: ' ',
          },
          component: () => import('../views/hbMarket/pages/productDetail.vue'),
        },
        {
          path: '/hbMarket/goodList',
          name: 'goodList',
          meta: {
            title: '商品列表',
            keepAlive: true,
          },
          component: () => import('../views/hbMarket/pages/goodList.vue'),
        },
        {
          path: '/hbMarket/myPosts',
          name: 'myPosts',
          meta: {
            title: '我发布的',
            keepAlive: true,
          },
          component: () => import('../views/hbMarket/pages/myPosts.vue'),
        },
        {
          path: '/hbMarket/mySales',
          name: 'mySales',
          meta: {
            title: '我卖出的',
            keepAlive: true,
          },
          component: () => import('../views/hbMarket/pages/mySales.vue'),
        },
        {
          path: '/hbMarket/myPurchases',
          name: 'myPurchases',
          meta: {
            title: '我买到的',
            keepAlive: true,
          },
          component: () => import('../views/hbMarket/pages/myPurchases.vue'),
        },
        {
          path: '/hbMarket/orderDetail',
          name: 'orderDetail',
          meta: {
            title: '订单详情',
          },
          component: () => import('../views/hbMarket/pages/orderDetail.vue'),
        },
        {
          path: '/hbMarket/productAudit',
          name: 'productAudit',
          meta: {
            title: '商品审核',
          },
          component: () => import('../views/hbMarket/pages/productAudit.vue'),
        },
      ],
    },
    {
      path: '/userInfoOpenAccount',
      name: 'userInfoOpenAccount',
      meta: {
        title: '用户基本信息开户',
      },
      component: () => import('../views/userInfoOpenAccount/index.vue'),
    },
    {
      path: '/userInfoOpenAccountEdit',
      name: 'userInfoOpenAccountEdit',
      meta: {
        title: '编辑持卡人信息',
      },
      component: () => import('../views/userInfoOpenAccount/edit.vue'),
    },
    {
      path: '/platformChart',
      name: 'platformChart',
      meta: {
        title: '平台报表',
      },
      component: () => import('../views/platformChart/platformChart.vue'),
    },
    {
      path: '/pledgeReward',
      name: 'pledgeReward',
      meta: {
        title: '社区奖励',
      },
      component: () => import('../views/pledgeReward/pledgeReward.vue'),
    },
    {
      path: '/transferDetails',
      name: 'transferDetails',
      meta: {
        title: '转入明细',
      },
      component: () => import('../views/pledgeReward/transferDetails.vue'),
    },
    {
      path: '/hbExchange',
      name: 'hbExchange',
      meta: {
        title: '红包兑换',
      },
      component: () => import('../views/hbExchange/hbExchange.vue'),
    },
    {
      path: '/register',
      name: 'register',
      meta: {
        title: '注册',
      },
      component: () => import('../views/register/register.vue'),
    },
    {
      path: '/IntegralLedger',
      name: 'IntegralLedger',
      meta: {
        title: '积分账本',
      },
      component: () => import('../views/IntegralLedger/IntegralLedger.vue'),
    },
    {
      path: '/rewardLedger',
      name: 'rewardLedger',
      meta: {
        title: '打赏账本',
        keepAlive: true,
      },
      component: () => import('../views/rewardLedger/rewardLedger.vue'),
    },
    {
      path: '/rewardLedgerDetail',
      name: 'rewardLedgerDetail',
      meta: {
        title: '打赏详情',
      },
      component: () => import('../views/rewardLedger/rewardLedgerDetail.vue'),
    },
    {
      path: '/attractInvestment',
      name: 'attractInvestment',
      meta: {
        title: '招商中心',
      },
      component: () => import('../views/attractInvestment/attractInvestment.vue'),
    },

    {
      path: '/infoSubmit',
      name: 'infoSubmit',
      meta: {
        title: '信息提交',
      },
      component: () => import('../views/infoSubmit/infoSubmit.vue'),
    },


    {
      path: '/404',
      component: () => import('@/views/404.vue'),
      meta: {
        title: '找不到页面',
      },
    },
    { path: '/:pathMatch(.*)*', redirect: '/404' },
  ],
});

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    window.document.title = (to?.meta?.title as string) || '';
  }
  next();
});

export default router;
